package com.zh.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

//driver=com.mysql.jdbc.Driver
//        url=jdbc:mysql://localhost:3306/db1?useUnicode=true&characterEncoding=UTF-8
//        username=root
//        password=root
public class JdbcConfiguration {
    @Value("${driver}")
    private String driver;
    @Value("${url}")
    private String url;
    @Value("${username}")
    private String username;
    @Value("${password}")
    private String password;

//     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
//        <property name="driverClassName" value="${driver}"></property>
//        <property name="url" value="${url}"></property>
//        <property name="username" value="${username}"></property>
//        <property name="password" value="${password}"></property>
//    </bean>
    @Bean("dataSource")
    public DataSource getDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
